#!/usr/bin/env python
#
#    Copyright (C) 2012 Gonzalo Bonigo <gonzalobonigo@gmail.com>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see http://www.gnu.org/licenses/
#


"""
    Este es un modulo ejecutable que permite analizar la diagnosticabilidad de un
    sistema de transiciones etiquetadas.
"""

__version__ = 3.1

import os.path
import time
import sys
import os

from daddyparsers import *
from lts import utils
import algorithms
import lts

# Cadenas para la funcion que imprime la ayuda del programa.

_msg_help_normal_mode_  = \
"""DADDY v3.1 - Diagnosability Analyzer for Distributed Discrete sYstems

It can run in three different modes:\n\n  -m = 0 | 1 | 2

Default mode is -m=0. Each mode implements different algorithms.
The way in which they work will not be explained here.

Arguments for mode -m=0:

  -s=S1,..,Sn ->  List of subsystems.
  -f=F1,..,Fm ->  List of faults.
  -c=C1,..,Ck ->  List of synchronization events.
  -h=0|...|6  ->  Heuristic selection. Default is 0.
  -g          ->  It tells DADDY to graphic non-diagnosable systems.
  -t          ->  It tells DADDY to count the time the analysis take.
  -v          ->  It tells DADDY to run in verbose mode.

Arguments for modea -m=1|2:

  -s=S1,..,Sn ->  List of subsystems.
  -f=F1,..,Fm ->  List of faults.
  -t          ->  It tells DADDY to count the time the analysis take.
  -v          ->  It tells DADDY to run in verbose mode."""


_msg_help_short_mode_  = "\nType 'daddy.py -help' for help."


def _print_help(mode='normal'):
    if mode == 'normal':
        print _msg_help_normal_mode_
    else:
        print _msg_help_short_mode_


if __name__ == '__main__':
    # Parseo los argumentos de entrada.
    try:
        parsed_args = parse(sys.argv[1:],1,8)
    except ParserError, (msg):
        print msg
        _print_help('short')
        sys.exit(0)
    if parsed_args["help"]:
        _print_help()
        sys.exit(0)
    if not parsed_args["fault_set"]:
        print "\nWarning! The fault list is empty. There will be no checking!"
    else:
        # Ejecuto el modo indicado.
        mode = parsed_args["mode"]
        if mode == 0:
            algorithms.lazy_diag_analyzer(parsed_args)
        if mode == 1:
            algorithms.quick_diagnosability_analyzer(parsed_args)
        if mode == 2:
            algorithms.twin_plant_method(parsed_args)
